package com.google.devrel.example.android.protips.mvp.view;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.devrel.example.android.protips.R;
import com.google.devrel.example.android.protips.mvp.IMonitorView;
import com.google.devrel.example.android.protips.mvp.MonitorPresenter;

public class MonitorTabletFragmentView extends Fragment implements IMonitorView {
	
	MonitorPresenter _presenter;

	public MonitorTabletFragmentView() {
		_presenter = new MonitorPresenter(this);
	}

	private View rootView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		rootView = inflater.inflate(R.layout.monitor_fragment, container,
				false);

		_presenter.fillViewContent(rootView, inflater.getContext());

		return rootView;
	}
	
	@Override
	public void setConnectivityStatus(boolean connectedOrConnecting,
			String typeName) {
		if (rootView != null) {
			TextView tv1 = (TextView) rootView.findViewById(R.id.monitor_connectivity);
			tv1.setText(connectedOrConnecting==true ? "connected" : "disconnected");
			
			TextView tv2 = (TextView) rootView.findViewById(R.id.monitor_connect_type);
			tv2.setText(typeName);
		}
	}

	@Override
	public void setBatteryStatus(String stat) {
		if (rootView != null) {
			TextView tv = (TextView) rootView.findViewById(R.id.monitor_battery);
			tv.setText(stat);
		}
	}
}
